package com.example.task1.util;

import com.google.gson.Gson;
import com.google.gson.JsonObject;

import org.json.JSONObject;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

import okhttp3.MediaType;
import okhttp3.RequestBody;

public class ApiUtils {

    public static int pageSize = 20;

    public static String getUrl(String url, HashMap<String, Object> map) {
        StringBuffer stringBuffer = new StringBuffer();
        Iterator<Map.Entry<String, Object>> iterator = map.entrySet().iterator();
        while (iterator.hasNext()) {
            Map.Entry<String, Object> next = iterator.next();
            if (stringBuffer.toString().isEmpty()) {
                stringBuffer.append("?");
            } else {
                stringBuffer.append("&");
            }
            stringBuffer.append(next.getKey()).append("=").append(next.getValue());
        }
        return url+stringBuffer.toString();
    }

    public static RequestBody getBody(HashMap<String,Object> map){
        MediaType mediaType = MediaType.parse("application/json");
        return RequestBody.create(mediaType, new JSONObject(map).toString());
    }

}
